const fs = require('fs')
const {pageTitleLocale} = require('../config')
const i18Diff = isOverwrite => {
	pageTitleLocale.forEach(item => {
		try {
			let oldContent = JSON.parse(fs.readFileSync(item.sass).toString())
			let newContent = JSON.parse(fs.readFileSync(item.my).toString())
			if(isOverwrite){
				Object.keys(newContent).forEach(key => {
					if(!oldContent[key]){
						oldContent[key] = newContent[key]
					}
				})
			}else{
				Object.keys(newContent).forEach(key => {
					oldContent[key] = newContent[key]
				})
			}
			fs.unlinkSync(item.sass)
			fs.writeFileSync(item.sass, JSON.stringify(oldContent))
		} catch (e) {
			console.log('文件不存在或写入文件出错，请检查翻译文件')
		}
	})
	
}
module.exports = {i18Diff}